import $ from "jquery";
import "../common/layer"
let com = {};

com.ajax = function (obj) {
  $.ajax({
    url: obj.url,
    data: obj.data ? obj.data : "",
    method: obj.method == undefined ? "get" : obj.method,
    xhrFields: {
      withCredentials: true
    },
    crossDomain: true,
  })
    .done(function (data) {
      obj.ok(data);
    })
    .fail(function (data) {
      if(data.status==401){
      }
      if (obj.fail instanceof Object) {
        obj.fail(data);
      } else {
        console.log(data);
      }
    });
  return this;
};

com.alertDialog = function(content){
  console.log(layer);
  layer.open({
    content: content
    ,btn: ['确定']
    ,yes: function(index){
      layer.close(index);
    }
  });
}

export default com;
